<?php if(!defined('BASEPATH')) exit('No direct script allowed');

class mdl_anggaran extends CI_Model{
	
	function __construct()
	{
		parent::__construct();
	}
	function kategori()	{		$this->db->select('*');		$this->db->from('kategori_mcm');		$this->db->order_by('id');  		return $this->db->get();	}		function parawaba()	{		$this->db->select('*');		$this->db->from('master_parawaba');		$this->db->order_by('nama','asc');  		return $this->db->get();	}
	function getItem($num=0, $offset=0)
	{
				$this->db->flush_cache();		$this->db->select('distinct(id_anggaran),tanggal,uraian,tahun,namafile');		$this->db->from('anggaran_post');		$this->db->order_by('id_anggaran');		$this->db->limit($num, $offset);		return $this->db->get();
	}	function get_anggaran($num=0, $offset=0)	{		$this->db->select('*');		$this->db->from('anggaran');  		$this->db->order_by('id', 'asc');		$this->db->limit($num, $offset);		return $this->db->get();	}
	 
	function getItemById($id)
	{
		$this->db->flush_cache();
		$this->db->where('id_anggaran', $id);
		return $this->db->get('anggaran_post');
	}
	function getItemBy($id)	{	/*		$this->db->select('*');		$this->db->from('anggaran');		//$this->db->where("tanggal BETWEEN '" . $periode_awal . "' AND '" . $periode_akhir .  "'");				$this->db->where("id_anggaran, $id"); 		return $this->db->get();				*/ 		$query="select * from anggaran where id_anggaran = '$id' ORDER BY parent";		$hasil = $this->db->query($query);		return $hasil;	}		function getItemByDate_Count($periode_awal,$periode_akhir)	{		$this->db->select('COUNT(anggaran.id) as jml');		$this->db->from('anggaran');		$this->db->where("tanggal BETWEEN '" . $periode_awal . "' AND '" . $periode_akhir .  "'");				$this->db->where("kredit != '0.00'"); 		return $this->db->get();	}	
	function insert($data)
	{
		$this->db->flush_cache();
		$this->db->insert('anggaran_post', $data);		$this->db->insert('anggaran_post_backup', $data);
	}
	function insert_data($data)	{		$this->db->flush_cache();		$this->db->insert('anggaran', $data);		$this->db->insert('anggaran_backup', $data);	}
	function update($id, $data)
	{
		$this->db->flush_cache();
		$this->db->where('id', $id);
		$this->db->update('anggaran', $data);
	}
	
	function delete($id)
	{
		$this->db->flush_cache();
		$this->db->delete('anggaran_post', array('id_anggaran' => $id));		$this->db->delete('anggaran', array('id_anggaran' => $id));
	}		function cek_tahun($tahun)	{		$query="select (id_anggaran) from anggaran_post where anggaran_post.tahun = $tahun";		$hasil = $this->db->query($query);		return $hasil->result();	}
		function delete_anggaran_post($id)	{		$this->db->flush_cache();		$this->db->delete('anggaran_post', array('tahun' => $id));		//$this->db->delete('anggaran', array('id_anggaran' => $id));	}		function delete_anggaran($id)	{		$this->db->flush_cache();		$this->db->delete('anggaran', array('id_anggaran' => $id));		//$this->db->delete('anggaran', array('id_anggaran' => $id));	}			function getTahun()	{		$query="select DISTINCT tahun, id_anggaran from anggaran_post ORDER BY tahun ASC";		//$this->db->flush_cache();		$result = $this->db->query($query);		return $result;		}			
}